package cn.com.git.workflow.interceptor;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zhangzhenfu
 * @Description
 * @date 2020/3/4 19:03
 */
public class ViewInterceptor extends HandlerInterceptorAdapter {
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView mv) throws Exception {
        if(mv!=null&&!StringUtils.isEmpty(mv.getViewName())){
            mv.addObject("cv", mv.getViewName());
            String path = request.getContextPath();
            String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
            mv.addObject("basePath",basePath);
            mv.addObject("ctx",path);
        }
    }
}
